package Game;
import java.util.ArrayList;

import org.newdawn.slick.SlickException;

//KNOWN BUGS OR CHECK: 
//* No check for IO images.
//* Go back to TileBased integers? And keep track of enemies in another way - separate array?


public class Map {
	
	/* The width of the map in tiles. */
	private static final int WIDTH = 16;
	
	/* The height of the map in tiles. */
	private static final int HEIGHT = 15;
	
	/* The width and height of each tile */
	public static final int TILESIZE = 50;
	
	/* The array holding each tile of the map */
	private Entity[][] field = new Entity[WIDTH][HEIGHT];
	
	/* The array holding every tower on the map. */
	private ArrayList<Tower> towers;
	
	/**
	 * Initiate the map.
	 * @throws SlickException 
	 */
	public Map() throws SlickException{
		towers = new ArrayList<Tower>();
	}
	
	/**
	 * Draw all tiles that aren't background
	 */
	public void drawMap(){
		// For each row
		for(int i = 0; i < WIDTH; i++){
			// For each column
			for(int j = 0; j < HEIGHT; j++){
				//If the field is something other than background - draw it.
				if(field[i][j] != null){
					field[i][j].draw();
				}
			}
		}
	}
	
	/**
	 * Return the Entity at a given position
	 * on the map. Return null if there is no Entity 
	 * @param x the x position on the map
	 * @param y the y position on the map
	 * @return the Entity if there is one, else false
	 */
	public Entity getEntity(int x, int y){
		return field[x][y];
	}
	
	/**
	 * Add a unit to a given place in the array.
	 * @param entity the entity to be added
	 * @param x the x value to be added at
	 * @param y the y value to be added at
	 */
	public void addUnit(Entity entity, int x, int y){
		field[x][y] = entity;
		if(entity instanceof Tower){
			towers.add((Tower)entity);
		}
	}
	
	/**
	 * Get all towers on the map.
	 */
	public ArrayList<Tower> getTowers(){
		return towers;
		
	}

	/**
	 * Checks if a given location is occupied or not
	 * @return <code>true</code> if the location is occupied
	 */
	public boolean isOccupied(int x, int y)
	{
		return field[x][y] == null ? false : true;
	}
	
}
